package org.oneblog.data.bean;

import java.util.List;

import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.oneblog.data.fields.ArticleAlbumField;
import org.oneblog.data.fields.SystemDataField;
import org.oneblog.data.util.PojoBeanCreator;
import org.springframework.util.CollectionUtils;

//文章专辑信息
public class ArticleAlbum {

	private String albumId;
	
	private String albumName;
	
	private String info;
	
	//存的是具体文章的ID
	private List<String> links;
	
	private String logo;
	
	private Long createTime;
	
	private Integer defunct;//是否删除；1：表示已删除；0：表示未删除
	
	public SolrInputDocument createDocument() {
		SolrInputDocument d = new SolrInputDocument();
		
		d.setField(ArticleAlbumField.DATA_ID, albumId);
		d.setField(ArticleAlbumField.DATA_TYPE, SystemDataField.SYSTEM_DATA_TYPE.ARTICLE_ALBUM);
		d.setField(ArticleAlbumField.ALBUM_NAME, this.albumName);
		d.setField(ArticleAlbumField.ALBUM_INFO, this.info);
		d.setField(ArticleAlbumField.ALBUM_LOGO, this.logo);
		d.setField(ArticleAlbumField.CREATE_TIME, this.createTime);
		d.setField(ArticleAlbumField.DEFUNCT, this.defunct != null && defunct > 0 ? 1 : 0);
		
		if(!CollectionUtils.isEmpty(links)) {
			for(String link : links) {
				d.addField(ArticleAlbumField.ARTICLE_LINKS, link);
			}
		}
		
		return d;
	}
	
	public static ArticleAlbum createFromDocument(SolrDocument d) {
		ArticleAlbum a = new ArticleAlbum();
		
		a.setAlbumId(PojoBeanCreator.getDocValue(d.get(ArticleAlbumField.DATA_ID)));
		a.setAlbumName(PojoBeanCreator.getDocValue(d.get(ArticleAlbumField.ALBUM_NAME)));
		a.setInfo(PojoBeanCreator.getDocValue(d.get(ArticleAlbumField.ALBUM_INFO)));
		a.setLinks(PojoBeanCreator.getStringValueList(d, ArticleAlbumField.ARTICLE_LINKS));
		a.setLogo(PojoBeanCreator.getDocValue(d.get(ArticleAlbumField.ALBUM_LOGO)));
		a.setCreateTime(PojoBeanCreator.getLongValue(d, ArticleAlbumField.CREATE_TIME, 0L));
		a.setDefunct(PojoBeanCreator.getIntValue(d, ArticleAlbumField.DEFUNCT, 1));
		
		return a;
	}
	
	public ArticleAlbum() {
	}

	public String getAlbumId() {
		return albumId;
	}

	public void setAlbumId(String albumId) {
		this.albumId = albumId;
	}

	public String getAlbumName() {
		return albumName;
	}

	public void setAlbumName(String albumName) {
		this.albumName = albumName;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public List<String> getLinks() {
		return links;
	}

	public void setLinks(List<String> links) {
		this.links = links;
	}

	public String getLogo() {
		return logo;
	}

	public void setLogo(String logo) {
		this.logo = logo;
	}

	public Long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public Integer getDefunct() {
		return defunct;
	}

	public void setDefunct(Integer defunct) {
		this.defunct = defunct;
	}
}
